<div id="setmain">
    <div class="modal-header ui-draggable-handle">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h4 class="modal-title" id="ntModalLabel2">{$title}</h4>
        <input type="hidden" name="" id="id" value="{$id|default=''}">
        <input type="hidden" name="" id="requestType" value="{$requestType|default=''}">
    </div>
    <div class="modal-body">
        <div class="row">
            <div class="col-md-12">
                <div class="alert alert-dismissable alert-info">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <p></p>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-6">
                <div class="col-md-12">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#">授权职务<span class="required"></span></a></li>
                    </ul>
                </div>
                <div class="col-md-12">
                    <div class="div-scroll" style="height: 26rem">
                        <table class="table table-hover ntTable">
                            <tbody>
                                <tr v-for="(item,index) in position">
                                    <td><label><input type="radio" name="setposition" :checked="positionId==item.id" @click="changePosition(item.id)"><span :style="{'padding-left':item.level*20+'px'}">{{item.langname}}</span></label></td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="col-md-6">
                <table class="table table-hover ntTable">
                    <tbody>
                        <tr>
                            <td>范围<span class="required"></span></td>
                            <td>
                                <div class="input-group">
                                    <input type="text" class="form-control text-right" v-model="scope">
                                    <span class="input-group-addon"> % </span>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>次数<span class="required"></span></td>
                            <td>
                                <div class="input-group">
                                    <input type="text" class="form-control text-right"  v-model="number">
                                    <span class="input-group-addon"> T </span>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>金额<span class="required"></span></td>
                            <td>
                                <div class="input-group">
                                    <input type="text" class="form-control text-right"  v-model="amount">
                                    <span class="input-group-addon"> BRL </span>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>取消</button>
        <button type="button" class="btn btn-primary" style="padding-left:24px;padding-right:24px" @click="saveFun"><span class="glyphicon glyphicon-floppy-disk"></span>保存</button>
    </div>
</div>
<script>
    new Vue({
        el:'#setmain',
        data:()=>({
            position:[],//授权职务
            positionId:'',//授权职务值
            scope:'',//范围
            number:'',//次数
            amount:'',//金额
        }),
        mounted(){
            this.getRpm()
            if($('#requestType').val() == 'edit'){
                this.getedit()
            }
        },
        methods:{
            //获取授权职务
            getRpm(){
                $.ajax({
                    url:'/admin/price/getPosition',
                    type:'post',
                    success:data=>{
                        data=JSON.parse(data)
                        this.position=data
                    }
                })
            },
            //修改职务事件
            changePosition(id){
                this.positionId=id
            },
            saveFun(){
                if($('#requestType').val() == 'add'){
                    var url = "/admin/price/positionprice?request=insert";
                }else{
                    var url = "/admin/price/positionpriceedit?request=update&id="+$('#id').val();
                }
                $.ajax({
                    url:url,
                    type:'post',
                    data:{
                        position_id:this.positionId,
                        range:this.scope,
                        qty:this.number,
                        amount:this.amount,
                    },
                    success:data=>{
                        data=JSON.parse(data)
                        change_mes_type('.alert',data.status)
                        if(data.status == 1){
                            $('.alert').show()
                            $('.alert p').html('*'+data.msg+'<br>')
                            $('#delmodel').val('true')
                            $('#price_discount_Modal').modal('hide')
                        }else{
                            $('.modal-body .alert').show()
                            $('.modal-body .alert p').html('*'+data.msg+'<br>')
                        }    
                    }
                })
            },
            //获取编辑数据
            getedit(){
                $.ajax({
                    url:"/admin/price/positionpriceedit?request=edit&id="+$('#id').val(),
                    type:'post',
                    success:data=>{
                        data=JSON.parse(data)
                        this.positionId = data.data.position_id
                        this.scope = data.data.range
                        this.number = data.data.qty
                        this.amount = data.data.amount
                    }
                })
            }

        }
    })
</script>